//
//  LoadTwoTableViewCell.m
//  STL_ Animation
//
//  Created by 孙健 on 16/4/8.
//  Copyright © 2016年 STL. All rights reserved.
//

#import "LoadTwoTableViewCell.h"
#import "STLLoadMv.h"
#import "STLoadModel.h"
@implementation LoadTwoTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.imageViewTitle = [[UIImageView alloc] initWithFrame:CGRectZero];
        self.labelCount = [[UILabel alloc] initWithFrame:CGRectZero];
        self.labelName = [[UILabel alloc] initWithFrame:CGRectZero];
        self.buttonLoad = [[UIButton alloc] initWithFrame:CGRectZero];
        self.progressView = [[UIProgressView alloc] initWithFrame:CGRectZero];
        self.progressView.progressTintColor = [UIColor redColor];
        
        self.labelName.font = [UIFont systemFontOfSize:14];
        self.labelCount.textColor = [UIColor colorWithRed:8/255.0 green:146/255.0 blue:114/255.0 alpha:1];
        //self.progressView.backgroundColor = [UIColor colorWithRed:8/255.0 green:146/255.0 blue:114/255.0 alpha:1];
        [self.buttonLoad setBackgroundImage:[[UIImage imageNamed:@"loadstop"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        

        self.dataSourceUrl = [NSMutableArray arrayWithCapacity:0];
        
        [self.contentView addSubview:self.imageViewTitle];
        [self.contentView addSubview:self.labelName];
        [self.contentView addSubview:self.labelCount];
        [self.contentView addSubview:self.buttonLoad];
        [self.contentView addSubview:self.progressView];
    }
    
    return self;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    self.imageViewTitle.frame = CGRectMake(0, 0, self.contentView.bounds.size.width/2 - 20, self.contentView.bounds.size.width/4);
    self.labelName.frame = CGRectMake(self.contentView.bounds.size.width/2 - 10, 10, self.contentView.bounds.size.width - self.contentView.bounds.size.width/2 - 40, (self.contentView.bounds.size.height - 30)/3);
    self.labelCount.frame = CGRectMake(self.contentView.bounds.size.width/2 - 10, (self.contentView.bounds.size.height - 30)/3 + 20, self.contentView.bounds.size.width - self.contentView.bounds.size.width/2 - 40, (self.contentView.bounds.size.height - 30)/3);
    
    self.progressView.frame = CGRectMake(self.contentView.bounds.size.width/2 - 10, (self.contentView.bounds.size.height - 30)/3 * 2 + 30, self.contentView.bounds.size.width - self.contentView.bounds.size.width/2 - 40, (self.contentView.bounds.size.height - 30)/3);
    
    self.buttonLoad.frame = CGRectMake( self.imageViewTitle.bounds.size.width + self.labelName.bounds.size.width + 20, self.contentView.bounds.size.height/3, self.contentView.bounds.size.height/3, self.contentView.bounds.size.height/3);
}

- (void)setLoadModel:(LoadViewModel *)loadModel {
    
    _loadModel = loadModel;
    [self.imageViewTitle sd_setImageWithURL:[NSURL URLWithString:loadModel.imageViewTitle]];
    self.labelName.text = loadModel.titleName;
    [self.buttonLoad addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
}



- (void)buttonAction:(UIButton *)button {
    
    self.block(self.count);
    if (self.isgoing == YES) {
        
        [self.buttonLoad setBackgroundImage:[[UIImage imageNamed:@"loadstop"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        self.isgoing = NO;
    }else {
        
        [self.buttonLoad setBackgroundImage:[[UIImage imageNamed:@"loadplay"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        self.isgoing = YES;
    }
}

@end
